//
//  UFOSXPMusicPageCollectionViewCell.m
//  unrivalledForUniverse
//
//  Created by dllo on 16/1/12.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "UFOSXPMusicPageCollectionViewCell.h"
#import "UFOMusicPageTableViewCell.h"
#import "UFOSXPMusicPageListModel.h"
@interface UFOSXPMusicPageCollectionViewCell () <UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, retain) UITableView *musicTableV;
@end
@implementation UFOSXPMusicPageCollectionViewCell

- (void)dealloc
{
    [_musicListArr release];
    [_musicTableV release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubviews];
    }
    return self;
}

// 重写setter方法
- (void)setMusicListArr:(NSMutableArray *)musicListArr
{
    if (_musicListArr != musicListArr) {
        [_musicListArr release];
        _musicListArr = [musicListArr retain];
    }
    [self.musicTableV reloadData];
    [self.musicTableV.mj_footer endRefreshing];
}

// 创建视图
- (void)createSubviews
{
    self.backgroundColor = [UIColor cyanColor];
    
    self.musicTableV = [UITableView new];
    self.musicTableV.delegate = self;
    self.musicTableV.dataSource = self;
    [self.contentView addSubview:self.musicTableV];
    
    [self.musicTableV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.edges.equalTo(self.contentView);
        
    }];
    [self.musicTableV registerClass:[UFOMusicPageTableViewCell class] forCellReuseIdentifier:@"musicCell"];
    
    // 上拉加载
    self.musicTableV.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(footerRefresh)];
    
}

// 动画
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    cell.layer.transform = CATransform3DMakeScale(0.1, 0.1, 1);
    [UIView animateWithDuration:0.5 animations:^{
        cell.layer.transform = CATransform3DMakeScale(1, 1, 1);
    }];
}
// 行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 80;
}
// 行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (self.musicListArr) {
        return self.musicListArr.count;
    };
    return 0;
}

// 自定义cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UFOMusicPageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"musicCell"];
    if (self.musicListArr) {
        UFOSXPMusicPageListModel *model = [self.musicListArr objectAtIndex:indexPath.row];
        cell.titleL.text = model.name;
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

// 上拉重载
- (void)footerRefresh
{
    [self.delegate getMoreMusicPageData];
}

@end
